<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户注册</title>
</head>
<link rel="stylesheet" href="css/modules/code.css">
<link rel="stylesheet" href="css/modules/laydate/default/laydate.css">
<link rel="stylesheet" href="css/modules/layer/default/layer.css">
<link rel="stylesheet" href="css/layui.css">
<link rel="stylesheet" href="css/registered.css">

<body>

    <div id="reistereds">

        <div id="reistereds_farme">
            <p id="reister_p1">
                用户注册
            </p>
            <form id="registerForm" action="/registerDone" method="POST">
            
                <p id="reister_p2">
                    <input type="text" id="reister_user" name="reister_user" required lay-verify="required" placeholder="输入注册账号"
                        autocomplete="off" class="layui-input">
                </p>
    
                <p id="reister_p3">
                    <input type="text" id="reister_pwd" name="reister_pwd" required lay-verify="required" placeholder="输入注册密码"
                        autocomplete="off" class="layui-input">
                </p>
                <p id="reister_p4">
                    <input type="text" id="reister_conpwd" name="reister_conpwd" required lay-verify="required" placeholder="确认注册密码"
                        autocomplete="off" class="layui-input">
                </p>
                <button type="button" id="gologin" class="layui-btn layui-btn-radius layui-btn-primary"
                    onclick="jump()">注册</button>
                <button type="button" id="gocancle" class="layui-btn layui-btn-radius layui-btn-primary"
                    onclick="quter()">取消</button>
                <p>
                    <button type="button" id="goback" class="layui-btn layui-btn-radius layui-btn-primary"
                        onclick="juout()">站主注册</button>
                </p>

            </form>


        </div><!-- reistereds_farme -->

</body>
<script src="js/jquery-3.6.0.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
    //注册
    function jump() {
        let username = $('#reister_user').val();
        let password = $('#reister_pwd').val();
        let confirmPassword = $('#reister_conpwd').val();
        if (username.length > 0 && password.length > 0 && password === confirmPassword) {
            $.ajax({
                url: "/registerDone",
                type: "POST",
                data: $('#registerForm').serialize(),
                dataType: "json",
                success: function (res) {
                    console.log(res);
                    if (res.code === 200) {
                        window.location.href = "/";
                    }
                }
            })
        } else {
            alert('请输入正确的账号或密码')
        }
    }
    //站主注册
    function juout() {
        window.location.href = '/backRegistered'
    }

    //取消
    function quter() {
        window.location.href = '/'
    }
</script>

</html>